/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package group2assignone.ucm.manager;

import group2assignone.dao.MyDAO;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.UITool;
import group2assignone.view.manager.DeleteAirportView;
import group2assignone.view.manager.ManagerView;

/**
 * Use Case: Delete Airport                                                 <br>
 * Pre-condition: User selects delete airport from Manager Main view.       <br>
 * Post-condition: UI is updated                                            <br>
 * 1. System retrieves selected airport                                     <br>
 * 2. System deletes airport                                                <br>
 * 3. Sytem closes delete airport view.                                     <br>
 * 4. Sytem updates UI to the manager main menu                             <br>
 * 5. System runs the use case UI Admin Main View                           <br>
 * 
 * 1. a) - User did not select an airport                                   <br>
 *       - System displays error message                                    <br>
 * @author group2                                                           <br>
 */
public class UCDeleteAirport implements UCController
{
    private DeleteAirportView view;

    public UCDeleteAirport(DeleteAirportView view){
        this.view = view;
    }

    public void run()
    {
        if (view.getSelectedRow() >= 0) {  //if have selection
            //1. System retrieves selected airport
            String airportLoc = view.getAirportLoc();
            //2. System deletes airport
            MyDAO coms = UCStartup.getInstance().getDAO();
            coms.sQLDeleteAirport(airportLoc);
            //3. Sytem closes delete airport view.
            view.dispose();
            //4. Sytem updates UI to the manager main menu
            ManagerView manView = ManagerView.getInstance();
            manView.go();
        } else {//1. a) - User did not select an airport
                //      - System displays error message
            UITool.displayError("Select an Airport to Delete!!!", view);
        }
    }
}
